﻿Imports MoniMisi2

Partial Class Controles_de_Usuario_Locacion
  Inherits System.Web.UI.UserControl
  Dim WebMethodRegionValor As String = ""
  Public Property WebMethodRegion() As String
    Get
      Return WebMethodRegionValor
    End Get
    Set(ByVal value As String)
      WebMethodRegionValor = value
    End Set
  End Property
  Dim WebMethodTerritorioValor As String = ""
  Public Property WebMethodTerritorio() As String
    Get
      Return WebMethodTerritorioValor
    End Get
    Set(ByVal value As String)
      WebMethodTerritorioValor = value
    End Set
  End Property

  Public Shared Function ManejoRegion(ByVal pContrato As MoniMisi2.ProveedorDatosServidor.Contrato) As MoniMisi2.ProveedorDatosServidor.Contrato
    Dim Contrato As MoniMisi2.ProveedorDatosServidor.Contrato = pContrato
    Dim Region As New NorthWindTableAdapters.RegionTableAdapter
    If Contrato.Operacion.Nombre = "Leer" Then
      Contrato = ProveedorDatosServidor.LeerFilas(Contrato, Region.Adaptador())
    End If
    Return Contrato
  End Function
  Public Shared Function ManejoTerritorio(ByVal pContrato As MoniMisi2.ProveedorDatosServidor.Contrato) As MoniMisi2.ProveedorDatosServidor.Contrato
    Dim Contrato As MoniMisi2.ProveedorDatosServidor.Contrato = pContrato
    Dim Territorio As New NorthWindTableAdapters.TerritoriesTableAdapter
    If Contrato.Operacion.Nombre = "Leer" And Not Contrato.Filtro Is Nothing Then
      Contrato = ProveedorDatosServidor.LeerFilas(Contrato, Territorio.Adaptador(Contrato.Filtro))
    End If
    Return pContrato
  End Function

  Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
    ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "ActualizaTerritorio", "function ActualizaTerritorio(pRegion,pTerritorio) {pTerritorio.control.Refrescar(true, pRegion.value);} ", True)
    ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "InicializaTerritorio", "function InicializaTerritorio(pRegion, pTerritorio) {if (pRegion.options.length == 1) {pRegion.value = pRegion.options[0].value;ActualizaTerritorio(pRegion, pTerritorio)}}", True)
    Me.ComboRegion.IdDatos = Me.Region.ClientID
    Me.ComboRegion.Attributes.Add("onchange", "ActualizaTerritorio(document.getElementById('" + Me.ComboRegion.ClientID + "'),document.getElementById('" + Me.ComboTerritorio.ClientID + "'))")
    Me.ComboRegion.Poblando = "function() {InicializaTerritorio(document.getElementById('" + Me.ComboRegion.ClientID + "'),document.getElementById('" + Me.ComboTerritorio.ClientID + "'))}"
    Me.ComboTerritorio.IdDatos = Me.Territorio.ClientID
    Me.Region.WebMethod = WebMethodRegion
    Me.Territorio.WebMethod = WebMethodTerritorio

  End Sub
End Class

